package architect.springcloud.gateway.zuul.controller;

import architect.springcloud.gateway.zuul.domain.UserInfo;
import architect.springcloud.gateway.zuul.repository.UserInfoRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;

/**
 * 用户Controller
 *
 * @author guanxin
 * @date 2018/5/3 11:11
 */

@RestController
@RequestMapping("/passport")
public class UserController {

    private UserInfoRepository userInfoRepository;
    private BCryptPasswordEncoder bCryptPasswordEncoder;

    public UserController(UserInfoRepository userInfoRepository,
                          BCryptPasswordEncoder bCryptPasswordEncoder) {
        this.userInfoRepository = userInfoRepository;
        this.bCryptPasswordEncoder = bCryptPasswordEncoder;
    }

    @PostMapping("/signup")
    public void signUp(@RequestBody UserInfo userInfo) {
        userInfo.setPassword(bCryptPasswordEncoder.encode(userInfo.getPassword()));
        userInfoRepository.save(userInfo);
    }

    @RequestMapping("/hello")
    @ResponseBody
    public String hello(){
        return "hello";
    }
}
